package main

import (
	"bufio"
	"fmt"
	"os"
)

// 面试题 s l 两个字符串
// ace
// abcde

// fgh
// abcde
// s必须被包含在l内, s的先后循序不能变

// 机考时候答题错误, 下面是机考后编写完成的. 以目前测试用例测试通过.
func main() {

	var s, l string

	scan := bufio.NewScanner(os.Stdin)
	scan.Split(bufio.ScanLines)

	for i := 0; i < 2; i++ {
		if scan.Scan() {
			if i == 0 {
				s = scan.Text()
			} else {
				l = scan.Text()
			}
		}
	}

	// res := -1
	left := -1
	isexist := false
	for i, v := range s {
		ts := string(v)

		for j, vl := range l {
			tl := string(vl)

			if ts == tl && i == 0 {
				left = j
				isexist = true
				break
			}

			if ts == tl && j > left {
				left = j
				isexist = true
				break
			}

		}
		if isexist {
			isexist = false
			continue
		} else {
			left = -1
		}

	}

	fmt.Println(left)
}
